package com.ruangong.GitClient.app.TravelExpense;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import com.ruangong.GitClient.R;
import android.widget.ArrayAdapter;
import com.ruangong.GitClient.app.TravelExpense.TravelEvent;


public class TravelEventsListAdapter extends ArrayAdapter<TravelEvent> {

    private List<TravelEvent> travelEvents;
    public TravelEventsListAdapter(Context context, List<TravelEvent> travelEvents) {
        super(context, 0, travelEvents);
        this.travelEvents=travelEvents;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_travelevent, parent, false);
            viewHolder = new ViewHolder();
            viewHolder.eventNameTextView = convertView.findViewById(R.id.textViewEventName);
            viewHolder.numberOfPeopleTextView = convertView.findViewById(R.id.textViewNumberOfPeople);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        TravelEvent travelEvent = getItem(position);
        viewHolder.eventNameTextView.setText(travelEvent.getName());
        viewHolder.numberOfPeopleTextView.setText(String.valueOf(travelEvent.getNumberOfPeople()));

        return convertView;
    }

    static class ViewHolder {
        TextView eventNameTextView;
        TextView numberOfPeopleTextView;
    }
}




